package thread2;

import java.util.concurrent.TimeUnit;

public class ThreadDemo3 implements Runnable {
    private int num = 10;

    @Override
    public void run() {
        while (num > 0) {
            try {
                TimeUnit.SECONDS.sleep(2);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName() + " 拿到了第" + num-- + "个资源");
        }
    }

    public static void main(String[] args) {
        ThreadDemo3 threadDemo3 = new ThreadDemo3();
        new Thread(threadDemo3, "1").start();
        new Thread(threadDemo3, "2").start();
        new Thread(threadDemo3, "3").start();
    }
}
